//
// Created by Felix on 24-4-23.
//

#ifndef GAZE_INDEXCONTROLLER_HPP
#define GAZE_INDEXCONTROLLER_HPP

#include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/macro/component.hpp"
#include "oatpp/core/macro/codegen.hpp"

#include "dto/DTOs.hpp"

#include OATPP_CODEGEN_BEGIN(ApiController)

class IndexController : public oatpp::web::server::api::ApiController {
public:
    explicit IndexController(
            OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)
    ) : oatpp::web::server::api::ApiController(objectMapper) {}

    static std::shared_ptr<IndexController> createShared(
            OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)
    ) {
        return std::make_shared<IndexController>(objectMapper);
    }

public:
    ENDPOINT_INFO(root) {
        info->addTag("Index");
        info->summary = "测试";
        info->description = "测试的描述";
        info->authorization = ""; // <-- 没有这一行，无法声明需要授权
        info->addSecurityRequirement("basic_auth");
        info->addResponse < Object < MessageDto<> >> (Status::CODE_200, "application/json");
        info->addResponse < Object < MessageDto<> >> (Status::CODE_401,
                "application/json", R"(输出：{"status_code":401,"status":"ERROR","message":"Unauthorized","data":[]})"
        );
    } // root
    ENDPOINT("GET", "/hello", root,
             BUNDLE(Int32, userId)) {
        auto dto = MessageDto<>::createShared();
        dto->statusCode = 200;
        dto->message = "Hello World! UserId: " + std::to_string(userId);
        // dto->data = oatpp::String("");
        // dto->data = oatpp::List<oatpp::Any>({});
        // dto->data = oatpp::Vector<String>({""});
        // dto->data = oatpp::PairList<String, String>({{"key", "string value"}});

        // 一个复杂的返回值
        // oatpp::Object<StatusDto> status = StatusDto::createShared();
        // status->status = "status";
        // status->code = 100;
        // status->message = "message";
        // auto data = oatpp::PairList<String, oatpp::Object<StatusDto> >::createShared();
        // data->emplace_back("key", status);
        // data->emplace_back("key_1", status);
        // data->emplace_back("key_2", status);
        // dto->data = oatpp::Vector<oatpp::PairList<String, oatpp::Object<StatusDto> > >({data});

        // 一个复杂的返回值
        oatpp::Object<MessageDto<>> status = MessageDto<>::createShared();
        status->status = "status";
        status->statusCode = 100;
        status->message = "message";
        auto data = oatpp::UnorderedMap<String, oatpp::Any>::createShared();
        data["key"] = status;
        data["key_string"] = oatpp::String("status");
        data["key_int_32"] = oatpp::Int32(100);
        dto->data = oatpp::Vector<oatpp::UnorderedMap<String, oatpp::Any> >({data});

        return createDtoResponse(Status::CODE_200, dto);
    }
};

#include OATPP_CODEGEN_END(ApiController)

#endif //GAZE_INDEXCONTROLLER_HPP
